<?php
include "include/config.inc.php";
if(!isset($_SESSION['s_activId']))
{
  header('location:checkLogin.php');
}

$selectVoucherType = "SELECT transmaster.voucherType,DATE_FORMAT(transmaster.transDate,'%d-%m-%Y')AS transDate,transmaster.voucherNo
                        FROM transdetail
                      LEFT JOIN transmaster ON transmaster.transMasterId = transdetail.transMasterId
                      WHERE transdetail.transMasterId = ".$_REQUEST['transMasterId'];
$selectVoucherTypeRes = mysql_query($selectVoucherType);
while($voucherTypeRow = mysql_fetch_array($selectVoucherTypeRes))
{
	$voucherType = $voucherTypeRow['voucherType'];
	$transDate   = $voucherTypeRow['transDate'];
	$voucherNo   = $voucherTypeRow['voucherNo'];
}


$drAmountTotal = 0;
$crAmountTotal = 0;
$crDetailArray = array();
$i=0;

$select = "SELECT transdetail.crAccountId,transdetail.crAmount,account.accountName AS crAccountName
             FROM transdetail
             JOIN account ON account.accountId = transdetail.crAccountId
            WHERE transMasterId = ".$_GET['transMasterId'];
$selectRes = mysql_query($select);
while($row = mysql_fetch_array($selectRes))
{
	$crDetailArray[$i]['crAccountId']   = $row['crAccountId'];
	$crDetailArray[$i]['crAccountName'] = $row['crAccountName'];
	$crDetailArray[$i]['crAmount']      = $row['crAmount'];
	$crAmountTotal += $row['crAmount'];
	$i++;
}
$drDetailArray = array();
$j=0;

$selectDr = "SELECT transdetail.drAccountId,transdetail.drAmount,account.accountName AS drAccountName
             FROM transdetail
             JOIN account ON account.accountId = transdetail.drAccountId
            WHERE transMasterId = ".$_GET['transMasterId'];
$selectDrRes = mysql_query($selectDr);
while($drRow = mysql_fetch_array($selectDrRes))
{
	$drDetailArray[$j]['drAccountId']   = $drRow['drAccountId'];
	$drDetailArray[$j]['drAccountName'] = $drRow['drAccountName'];
	$drDetailArray[$j]['drAmount']      = $drRow['drAmount'];
	$drAmountTotal += $drRow['drAmount'];
	$j++;
}
include("bottom.php");
$smarty->assign('crDetailArray',$crDetailArray);  
$smarty->assign('drDetailArray',$drDetailArray);  
$smarty->assign('crAmountTotal',$crAmountTotal);  
$smarty->assign('drAmountTotal',$drAmountTotal);  
$smarty->assign('voucherType',$voucherType);  
$smarty->assign('transDate',$transDate);  
$smarty->assign('voucherNo',$voucherNo);  
$smarty->display('voucherDetail.tpl');  
?>